package com.wanczy.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wanczy.pojo.Cart;
import com.wanczy.pojo.Shop;
import com.wanczy.pojo.ShowCartGoods;
import com.wanczy.pojo.User;
import com.wanczy.service.CartService;

@Controller
public class CartController {
    @Autowired
	private CartService cartService;
    /*
     * 通过ID查看我的购物车里所有的商品
     */
    @RequestMapping("/Carts")
    public String getAllCart(@RequestParam(value="userId") Integer userId,Map<String,Object> map) {
    	System.out.println(userId);
    	List<ShowCartGoods> list =  cartService.getMyCart(userId);
    	System.out.println(list);
    	map.put("carts", list);
    	
    	/*User us = SystemSession.get();
		System.out.println(us);*/
		return "/cart/Carts";
    	
    }
    /*@RequestMapping("/Carts")
    public ModelAndView getAllCartShop(@RequestParam(value="userId") Integer userId,ModelAndView views) {
    	//Map<String,Object> map = new HashMap<String,Object>();
    	List<Shop> list =  cartService.getMyCartShop(userId);
    	System.out.println(list);
    	views.addObject("cartshop", list);
    	
    	//map.put("cartshop", list);
    	List<ShowCartGoods> list1 =  cartService.getMyCart(userId);
    	System.out.println(list1);
    	views.addObject("carts", list1);
    	
    	views.setViewName("/cart/Carts");
    	//map.put("carts", list);
		//return "/cart/Carts";
    	return views;
    	
    }*/
    //删除购物车商品
    @ResponseBody
    @RequestMapping("/deletecart")
    public List<Integer> deleteCart(@RequestParam("cartId") Integer cartId){
       /* //判断用户是否为登录状态
        User user = (User) request.getAttribute("user");
        if (user != null){*/
            int cart = cartService.getDelCart(cartId);
            List<Integer> list = new ArrayList<Integer>();
            list.add(cart);
            return list;
       // }
    }
  //修改购物车商品数量
    
   /* @RequestMapping(value="/cart/update/num/{itemId}/{num}",method=RequestMethod.POST)
    @ResponseBody
    public List<Integer> updCartNum(@PathVariable Integer itemId,@PathVariable Integer num){
             
            int cartNum = cartService.getUpdCartNum(itemId,num);
            List<Integer> list = new ArrayList<Integer>();
            list.add(cartNum);
            return list;
    }*/
}

